package com.lookme.lmtool.model;

import com.lookme.lmtool.cracker.filter.IFilter;
import com.lookme.lmtool.cracker.spliter.ISpliter;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 项目信息
 * @author blake
 */
@Data
@NoArgsConstructor
@XStreamAlias("item")
public class ItemInfo implements Serializable {
    public static final long serialVersionUID=-3059498077086480447L;
    @XStreamAsAttribute
    String id;
    /**
     * 项目名称
     */
    @XStreamAsAttribute
    String name;

    /**
     * 图像地址
     */
    @XStreamAsAttribute
    String url;

    @XStreamAlias("filters")
    /**
     * 滤镜列表
     */
    List<IFilter> filterList;

    @XStreamAlias("spliter")
    /**
     * 分割方式
     */
    ISpliter spliter=null;

    @XStreamAlias("charAspects")
    /**
     * 字符特征列表
     */
    List<CharAspect> charAspectList;

    /**
     * 下载脚本配置
     */
    String downScript;

    /**
     * 获取OCR脚本
     */
    String ocrScript;
    public ItemInfo(String id,String name){
        this.id=id;
        this.name=name;
    }

    public void addFilter(IFilter filter){
        if(filterList==null){
            filterList=new ArrayList<>();
        }
        filterList.add(filter);
    }

    public boolean addCharAspect(CharAspect charAspect) {
        if(charAspectList==null){
            charAspectList=new ArrayList<>();
        }
        for(CharAspect existCharAspect:charAspectList){
            if(charAspect.getValue().equals(existCharAspect.getValue())){
                existCharAspect.setKey(charAspect.getKey());
                return false;
            }
        }
        charAspectList.add(charAspect);
        return true;
    }
}
